import React, { Component } from 'react';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import { createBottomTabNavigator } from 'react-navigation-tabs';

import { Icon, Text } from 'native-base';
import { Colors } from './theme';


// 模块引入
import HomeScreen from "./view/Home"; // 首页
import UpWebViewScreen from "./component/UpWebView"; // webView

// 消息模块
import MessageScreen from "./view/massage/Message"; // 公告
import MessageDetailsScreen from "./view/massage/MessageDetails"; // 公告详情

// 分享模块
import InviteFriendsScreen from "./view/share/InviteFriends"; // 邀请好友分享

// 大厅 - 模块引入
import LobbyScreen from "./view/Lobby"; // 大厅

// 发布 - 模块引入
import PublishScreen from "./view/Publish"; // 发布
import OrderPlaceScreen from "./view/publish/OrderPlace"; // 发布预算
import KanjiaHbScreen from "./view/publish/KanjiaHb"; // 砍价红包
import ToupiaoGzScreen from "./view/publish/ToupiaoGz"; // 转发类
import ZhuanfaFxScreen from "./view/publish/ZhuanfaFx"; // 转发类
import XiazaiZcScreen from "./view/publish/XiazaiZc"; // 注册类型

// 活动 - 模块引入
import ActivityScreen from "./view/Activity"; // 活动

// 交易 - 模块引入
import MyTransactionScreen from "./view/transaction/MyTransaction"; // 我的交易记录

// 用户 - 模块引入
import UsersScreen from "./view/Users"; // 用户
import LoginScreen from "./view/user/Login"; // 登录
import RegisterScreen from "./view/user/Register"; // 注册
import SettingScreen from "./view/user/Setting"; // 设置
import ForgetPasswordScreen from "./view/user/ForgetPassword"; // 忘记密码
import ChangePasswordScreen from "./view/user/ChangePassword" // 修改密码
import UserCenterScreen from "./view/user/UserCenter"; // 用户中心
import UserLevelScreen from "./view/user/UserLevel"; // 用户等级
import UserStarScreen from "./view/user/UserStar"; // 星级达人
import RealnameAutoScreen from "./view/user/RealnameAuto"; // 实名认证
import ReceiptAccountScreen from "./view/user/ReceiptAccount" // 账户认证
import ProblemBackScreen from "./view/user/ProblemBack" // 问题反馈
import MyteamScreen from "./view/user/Myteam" // 我的团队

// 用户协议与教程
import PrivacyPolicyScreen from "./view/document/PrivacyPolicy";  // 隐私条款
import ServiceAgreementScreen from "./view/document/ServiceAgreement"; // 服务协议
import CourseTaskScreen from "./view/document/CourseTask"; // 新手指南
import CourseDetailsScreen from "./view/document/CourseDetails"; // 指南详情

// 工具箱 - 模块引入
import DeviceInfoScreen from "./view/holdall/DeviceInfo"; // 设备信息
import GeolocationScreen from "./view/holdall/Geolocation"; // 定位信息
import QrcodeScreen from "./view/holdall/Qrcode"; // 二维码
import VibrationpScreen from "./view/holdall/Vibrationp"; // 振动器
import OpenLinkScreen from "./view/holdall/OpenLink"; // 地址打开
import ScanningScreen from "./view/holdall/Scanning"; // 扫描器


// 首页 - 路由部署
const HomeStack = createStackNavigator({
  Home: { screen: HomeScreen },
  UpWebView: { screen: UpWebViewScreen },
  Message: { screen: MessageScreen },
  MessageDetails: { screen: MessageDetailsScreen },
  InviteFriends: { screen: InviteFriendsScreen },
  CourseTask : { screen: CourseTaskScreen },
}, {
  headerMode: 'none',
});

HomeStack.navigationOptions = ({ navigation }) => {
  let { routeName } = navigation.state.routes[navigation.state.index];
  let navigationOptions = {};
  if (routeName === 'InviteFriends') {
    navigationOptions.tabBarVisible = false;
  }
  return navigationOptions;
};

// 大厅 - 路由部署
const LobbyStack = createStackNavigator({
  Lobby: { screen: LobbyScreen },
}, {
  headerMode: 'none',
});


// 发布 - 路由部署
const PublishStack = createStackNavigator({
  Publish: { screen: PublishScreen },
  KanjiaHb: { screen: KanjiaHbScreen},
  ToupiaoGz: { screen: ToupiaoGzScreen},
  ZhuanfaFx: { screen: ZhuanfaFxScreen},
  XiazaiZc: { screen: XiazaiZcScreen},
  OrderPlace: { screen: OrderPlaceScreen},
}, {
  headerMode: 'none',
});

// 活动 - 路由部署
const ActivityStack = createStackNavigator({
  Activity: { screen: ActivityScreen },
  DeviceInfo: { screen: DeviceInfoScreen },
  Geolocation: { screen: GeolocationScreen },
  Qrcode: { screen: QrcodeScreen },
  Vibrationp: { screen: VibrationpScreen },
  OpenLink: { screen: OpenLinkScreen },
  Scanning: { screen: ScanningScreen },
}, {
  headerMode: 'none',
});

// 我的 - 路由部署
const UsersStack = createStackNavigator({
  Users: { screen: UsersScreen },
  UserCenter: { screen: UserCenterScreen },
  UserLevel: {screen: UserLevelScreen},
  UserStar: {screen: UserStarScreen},
  Login: { screen: LoginScreen },
  Register: { screen: RegisterScreen },
  Setting: { screen: SettingScreen },
  ChangePassword: { screen: ChangePasswordScreen },
  ForgetPassword: { screen: ForgetPasswordScreen },
  RealnameAuto:  { screen: RealnameAutoScreen },
  ReceiptAccount: { screen: ReceiptAccountScreen },
  Scanning: { screen: ScanningScreen },
  MyTransaction: { screen: MyTransactionScreen},
  InviteFriends : { screen: InviteFriendsScreen },
  Message: { screen: MessageScreen },
  ProblemBack: { screen: ProblemBackScreen },
  Myteam: { screen: MyteamScreen},
  PrivacyPolicy: { screen: PrivacyPolicyScreen },
  ServiceAgreement: { screen: ServiceAgreementScreen },
  CourseTask: { screen: CourseTaskScreen },
  CourseDetails: { screen: CourseDetailsScreen },
  
}, {
  headerMode: 'none',
});

UsersStack.navigationOptions = ({ navigation }) => {
  let { routeName } = navigation.state.routes[navigation.state.index];
  let navigationOptions = {};
  if (routeName === 'InviteFriends') {
    navigationOptions.tabBarVisible = false;
  }
  if (routeName === 'PrivacyPolicy') {
    navigationOptions.tabBarVisible = false;
  }
  if (routeName === 'ServiceAgreement') {
    navigationOptions.tabBarVisible = false;
  }
  return navigationOptions;
};

// 底部按钮
export default createAppContainer(createBottomTabNavigator(
  {
    HomeStack: {
      screen: HomeStack,
      navigationOptions: {
        title: "首页",
        tabBarLabel: ''
      }
    },
    LobbyStack: {
      screen: LobbyStack,
      navigationOptions: {
        title: "大厅",
        tabBarLabel: ''
      }
    },
    PublishStack: {
      screen: PublishStack,
      navigationOptions: {
        title: "发布",
        tabBarLabel: ''
      }
    },
    ActivityStack: {
      screen: ActivityStack,
      navigationOptions: {
        title: "活动",
        tabBarLabel: ''
      }
    },
    UsersStack: {
      screen: UsersStack,
      navigationOptions: {
        title: "我的",
        tabBarLabel: ''
      }
    }
  },
  {
    defaultNavigationOptions: ({ navigation }) => ({
      tabBarIcon: ({ focused, tintColor }) => {
        const { routeName } = navigation.state;
        let iconName;
        switch (routeName) {
          case 'HomeStack':
            iconName = 'home';
            break;
          case 'LobbyStack':
            iconName = 'compass';
            break;
          case 'PublishStack':
            iconName = 'telegram';
            break;
          case 'ActivityStack':
            iconName = 'calendar';
            break;
          case 'UsersStack':
            iconName = 'user';
            break;
          default:
            iconName = 'grav';
            break;
        }

        return <Icon type="FontAwesome" name={iconName} style={{ fontSize: 24, color: tintColor }} />;
      },
    }),
    tabBarOptions: {
      activeTintColor: Colors.subject,
      inactiveTintColor: Colors.inactive,
    },
  }
));


